#include "projectmanager.h"
#include <QFile>
#include <QTextStream>

ProjectManager::ProjManagerPtr ProjectManager::m_ProjectManagerPtr = 0;

ProjectManager::ProjectManager()
{

}

ProjectManager::~ProjectManager()
{

}

ProjectManager::ProjManagerPtr ProjectManager::Instance()
{
	if (!m_ProjectManagerPtr)
		m_ProjectManagerPtr.reset(new ProjectManager);
	return m_ProjectManagerPtr;
}

bool ProjectManager::LoadProjectFile(const QString &filename)
{
	QFile profile(filename);
	if (!profile.open(QIODevice::ReadOnly | QIODevice::Text))
		return false;

	m_ProjectFile = filename;
	m_HeaderFiles.clear();
	m_SourceFiles.clear();

	QTextStream stream(&profile);
	QString line=stream.readLine();
	int filetype = -1;
	while (!line.isEmpty())
	{
		if (line == QString("HEADER_BEGIN"))
		{
			filetype = EnumFileType_HeaderFile;
			line = stream.readLine();
		}
		if (line == QString("SOURCE_BEGIN"))
		{
			filetype = EnumFileType_SourceFile;
			line = stream.readLine();
		}
		if (filetype==EnumFileType_HeaderFile)
			m_HeaderFiles.push_back(line);
		if (filetype==EnumFileType_SourceFile)
			m_SourceFiles.push_back(line);

		line = stream.readLine();
	}

	return true;
}

bool ProjectManager::SaveProjectFile()
{
	return true;
}